/**
 * @author v_wangyan
 * @date 2013-01-06
 */ 
var bd = window.bd || {};
var buttonPos = [];
var animationTemp = {};
var tnItem = {
	'play0929': 'play0929',
	'hptest01': 'play0929',
	'hptest02': 'play0929'
};
/**
 * 获取元素对象
 * @param  {string} element 元素id
 * @return {object}         返回元素对象
 */
bd.g = function(element) {
    return document.getElementById(element) || element;
},
/**
 * 转换JSON对象
 * @param  {string} jsonString json字符串
 * @return {object}            json对象
 */
bd.jsonDecode =function(jsonString) {
	return (new Function("return " + jsonString))();
},
/**
 * 显示dom
 * @param  {string} id dom的id
 * @return {void}    无
 */

bd.show = function(id) {
	bd.isShow(id, true);
},
/**
 * 隐藏dom
 * @param  {string} id dom的id
 * @return {void}    无
 */
bd.hide = function(id) { 
    bd.isShow(id, false);
},
/**
 * 添加样式
 * @param {string|object} element   目标元素
 * @param {string} className 样式名称
 */
bd.addClass = function(element, className) { 
	element = bd.g(element)||element;
    var classArray = className.split(/\s+/),
        result = element.className,
        classMatch = " " + result + " ",
        i = 0,
        l = classArray.length;

    for (; i < l; i++) {
         if ( classMatch.indexOf( " " + classArray[i] + " " ) < 0 ) {
             result += (result ? ' ' : '') + classArray[i];
         }
    }

    element.className = result;
},
/**
 * 移除样式
 * @param  {string|object} element   目标元素
 * @param  {string} className 样式名称
 * @return {void}           无
 */
bd.removeClass = function(element, className) { 
	element = bd.g(element)||element; 

    var oldClasses = element.className.split(/\s+/),
        newClasses = className.split(/\s+/),
        lenOld,
        lenDel = newClasses.length,
        j,
        i = 0;  
    for (; i < lenDel; ++i) {
        for(j = 0, lenOld = oldClasses.length; j < lenOld; ++j) {
            if (oldClasses[j] == newClasses[i]) {
            	oldClasses.splice(j, 1);
            	break;
            }
        }
    }
    element.className = oldClasses.join(' ');
},
/**
 * 是否显示
 * @return {bool} 返回布尔值
 */
bd.isShow = function(id, flag) {
    bd.g(id).style.visibility = flag ? 'visible' : 'hidden';
},
bd.wheelEvent = function (elem, func){
    if(elem.attachEvent){
        elem.attachEvent("onmousewheel",func);
    }else if(elem.addEventListener){
        elem.addEventListener("DOMMouseScroll",func);
    }
},
bd.animate = {
	/**
	 * 调用效果处理函数
	 * @param  {string}   domid        
	 * @param  {object}   element      目标元素
	 * @param  {string|object}   propertyname 样式(集合)
	 * @param  {number|object}   startvalue   起始状态
	 * @param  {number}   endvalue     结束状态
	 * @param  {number}   duration     持续时间
	 * @param  {Function} callback     自定义动画参数
	 * @return {boid}                无
	 */
	slider: function (domid, element, propertyname, startvalue, endvalue, duration, callback, slideType) {
		if(animationTemp[domid]){
			// animationTemp[domid].stop();
			// animationTemp[domid] = null;
			return;
		}
		duration = /msie/i.test(navigator.userAgent) ? duration / 3 : duration;
		if(element.getAttribute('data-isTweenShow') == 'true'){
			return;
		}
		element.setAttribute('data-isTweenShow', 'true');
		animationTemp[domid] = new SchAIM.Tween(element, propertyname, startvalue, endvalue, (slideType || bd.sliderType), duration, function () {
			animationTemp[domid].stop();
			delete animationTemp[domid];
			callback && callback();
		});
		
	},
	funcSlider: function (slide, callback) {  
		var cfg = config.sliderInfo[slide.pageType],
			arr = {}; 
		if (bd.sliderTop == 1) {
			if (bd.statu[slide.statuIndex]) {
				return;
			}	
					
			arr['startVal_' + slide.tag] = 0;
			arr['endVal_' + slide.tag] = cfg[slide.tag][slide.type];					
		} else {	
			if (!bd.statu[slide.statuIndex]) {
				return;
			}	
				
			arr['startVal_' + slide.tag] = cfg[slide.tag][slide.type];
			arr['endVal_' + slide.tag] = 0;			
		}		
		
		arr.id = cfg[slide.tag].id;
		arr.timer = cfg[slide.tag].timer;
		if (bd.sliderTop == 1 && cfg[slide.tag].delay) {
			cfg[slide.tag].slider = window.setTimeout(function () {
				callback && callback(arr);
			}, cfg[slide.tag].delay);
		} else { 
			callback && callback(arr);			
		}
	},
	proccessSlider: function (item, propertyname, startvalue, endvalue, func) {
		var duration = 0;
		bd.animate.funcSlider({
			pageType: item.pageType,
			tag: item.tag,
			statuIndex: item.statuIndex,
			type: item.type
		}, function (param) { 	
			propertyname.push(item.type);
			startvalue.push(param['startVal_' + item.tag]); 
			endvalue.push(param['endVal_' + item.tag]);
			duration = (param.timer / 1000);
			bd.animate.slider(param.id, bd.g(param.id), propertyname, startvalue, endvalue, duration, func);
		});
	}
},
/**
 * 判断鼠标滚轮方向
 * @param  {number} scrollTop 当前滚动位置
 * @return {number}           滚动方向 1:向下 -1: 向上
 */
bd.scrollType = function (scrollTop) {	
	return (bd.prevTop < scrollTop) ? 1 : -1;	
},
bd.pageTopValue = function (cfg, pageIndex) {
	return cfg.headHeight + cfg.boxHeight * pageIndex - bd.getInnerHeight();
},
bd.pageDownValue = function (cfg, pageIndex, element) {
	// return bd.pageTopValue(cfg, pageIndex) + parseInt(bd.css(bd.g(element), 'bottom'));
	return bd.pageTopValue(cfg, pageIndex) + cfg.boxHeight * pageIndex - parseInt(bd.css(bd.g(element), 'bottom'));
},
bd.isOutofView = function(cfg, pageIndex, element, scrollTop){
	var dom = bd.g(element); 
	var top = parseInt(dom.getAttribute('data-top') || '0');
	var height = parseInt(dom.getAttribute('data-height') || '0');
	var pageHeight = bd.getInnerHeight();
	var t = cfg.headHeight + cfg.boxHeight * pageIndex - bd.getInnerHeight();
	
	// if (pageIndex == 7) {
	// 	document.title = 't=' + t + '||' + top;
	// }

	if(scrollTop >= t && scrollTop < t + pageHeight){ 
		dom.setAttribute('data-isShow', 'false');
		return false;
	}else{
		dom.setAttribute('data-isShow', 'true');
		return true;
	}
},
bd.setElementsSlideUp = function (len, type, statuIndex) {
	for (var i = 0; i < len; i++) {
		if (config.sliderInfo[type][i].id && bd.g(config.sliderInfo[type][i].id)) {
			bd.show(config.sliderInfo[type][i].id);
		}
		bd.animate.proccessSlider({pageType: type, tag: i, statuIndex: statuIndex, type: 'height'}, [], [], []);
	}
},
bd.setElementSlideDown = function (cfg, len, type, statuIndex) {
	var cfgPage = config.sliderInfo[type],
		id = '';
	for (var i = 0; i < len; i++) {	
		id = cfgPage[i].id || '';
		bd.animate.proccessSlider({pageType: type, tag: i, statuIndex: 0, type: 'height'}, [], [], [], function () {			
			if (id && bd.g(id)) {
				bd.hide(id);
			}
		});	
	}
}
/**
 * 获取元素的样式表样式
 * @param  {object} obj       目标元素
 * @param  {string} attribute 样式名称
 * @return {string}           样式值
 */
bd.css = function (obj, attribute) { 
	 return obj.currentStyle?obj.currentStyle[attribute]:document.defaultView.getComputedStyle(obj,false)[attribute];   
},
bd.getInnerHeight = function () {
	return bd.getInnerSize('Height');
},
bd.getInnerWidth = function () {
	return bd.getInnerSize('Width');
},
/**
* 获取可视区域尺寸
* 兼容doctype获取浏览器可视区域的高度
* 根据document.compatMode 模式，判断是 CSS1Compat 还是BackCompat
* xhtml 1.0的Strict 与 Transitional 都是：BackCompat
* html或者html5的都是：CSS1Compat
*/
bd.getInnerSize = function (type) {
	return document.compatMode == 'CSS1Compat' ? document.documentElement['client' + type] : document.body['client' + type]
},
bd.scrollPageElement = function (scrollTop, direction) {  
	var cfg = config.boxType[screenType];
	var cfgSlider = config.sliderInfo; 
	if (bd.isOutofView(cfg, 1, 'searchHand', scrollTop)) {	 
		// 搜索增强								
		bd.setStyles(bd.g("searchSlidebox"), {
			height: '0px'
			,visibility: 'hidden'
		});	
		bd.setStyles(bd.g("searchHand"), {
			height: '0px'
			,visibility: 'hidden'
		});
		if (animationTemp['textbar']) {
			animationTemp['textbar'].stop();
			delete animationTemp['textbar'];
		}
		bd.setStyles(bd.g("textbar"), {
			left: '276px'
			,width: '317px'
			,visibility: 'visible'
		});

		bd.g("searchSlidebox").setAttribute('data-isTweenShow', 'false');	
		bd.g("searchHand").setAttribute('data-isTweenShow', 'false');	
		bd.g("textbar").setAttribute('data-isTweenShow', 'false');				
	}else{
		// 搜索增强			
		bd.animate.slider('searchSlidebox', bd.g("searchSlidebox"), ['height'], [0], [151], 1, function(){});
		bd.animate.slider('textbar', bd.g("textbar"), ['width', 'left'], [317, 276], [0, 593], 1.4, function(){});	
		bd.animate.slider('searchHand', bd.g("searchHand"), ['height', 'left'], [56, 262], [56, 578], 1.4, function(){});			
		bd.show('searchSlidebox');
		bd.show('textbar');
		bd.show('searchHand');	
	}
	if (bd.isOutofView(cfg, 2, 'imgHand', scrollTop)) {  
		// 搜图增强		
		bd.setStyles(bd.g("imgHand"), {
			height: '0px'
			,visibility: 'hidden'
		});		
		bd.g("imgHand").setAttribute('data-isTweenShow', 'false');		
	}else{ 
		// 搜图增强
		bd.animate.slider('imgHand', bd.g("imgHand"), ['height'], [0], [56], 0.8, function(){});
		bd.show('imgHand');	
	}
	if (bd.isOutofView(cfg, 3, 'tiebaBox1', scrollTop)) {
		// // 贴吧神器							
		bd.setStyles(bd.g("tiebaBox1"), {
			height: '0px'
			,visibility: 'hidden'
		});	
		bd.setStyles(bd.g("tiebaBox2"), {
			height: '0px'
			,visibility: 'hidden'
		});		
		bd.g("tiebaBox1").setAttribute('data-isTweenShow', 'false');
		bd.g("tiebaBox2").setAttribute('data-isTweenShow', 'false');
	}else{			
		// 贴吧神器
		bd.animate.slider('tiebaBox1', bd.g("tiebaBox1"), ['height'], [0], [249], 0.6, function(){});
		bd.animate.slider('tiebaBox2', bd.g("tiebaBox2"), ['height'], [0], [213], 0.3, function(){});		
		bd.show('tiebaBox1');
		bd.show('tiebaBox2');
	}
	// if (bd.isOutofView(cfg, 4, 'musicBox1', scrollTop)) {
	// 	// // 百度随身听							
	// 	bd.setStyles(bd.g("musicBox1"), {
	// 		height: '0px'
	// 		,visibility: 'hidden'
	// 	});	
	// 	bd.setStyles(bd.g("musicBox2"), {
	// 		height: '0px'
	// 		,visibility: 'hidden'
	// 	});	
	// 	bd.setStyles(bd.g("musicBox3"), {
	// 		height: '0px'
	// 		,visibility: 'hidden'
	// 	});	
	// 	bd.g("musicBox1").setAttribute('data-isTweenShow', 'false');
	// 	bd.g("musicBox2").setAttribute('data-isTweenShow', 'false');
	// 	bd.g("musicBox3").setAttribute('data-isTweenShow', 'false');
	// }else{			
	// 	// 百度随身听
	// 	bd.animate.slider('musicBox1', bd.g("musicBox1"), ['height'], [0], [44], 0.6, function(){});
	// 	bd.animate.slider('musicBox2', bd.g("musicBox2"), ['height'], [0], [72], 0.6, function(){});
	// 	bd.animate.slider('musicBox3', bd.g("musicBox3"), ['height'], [0], [66], 0.6, function(){});			
	// 	bd.show('musicBox1');
	// 	bd.show('musicBox2');
	// 	bd.show('musicBox3');
	// }
	// if (bd.isOutofView(cfg, 5, 'panBox1', scrollTop)) {
	// 	// // 网盘增强				
	// 	bd.setStyles(bd.g("panBox1"), {
	// 		height: '0px'
	// 		,visibility: 'hidden'
	// 	});
	// 	bd.setStyles(bd.g("panBox2"), {
	// 		height: '0px'
	// 		,visibility: 'hidden'
	// 	});
	// 	bd.setStyles(bd.g("panBox3"), {
	// 		height: '0px'
	// 		,visibility: 'hidden'
	// 	});
	// 	bd.setStyles(bd.g("panBox4"), {
	// 		height: '0px'
	// 		,left: cfgSlider.pan[3].left[screenType].start + 'px'
	// 		,visibility: 'hidden'
	// 	});	
	// 	bd.g("panBox1").setAttribute('data-isTweenShow', 'false');
	// 	bd.g("panBox2").setAttribute('data-isTweenShow', 'false');
	// 	bd.g("panBox3").setAttribute('data-isTweenShow', 'false');
	// 	bd.g("panBox4").setAttribute('data-isTweenShow', 'false');
	// }else{			
	// 	// 网盘增强		
	// 	bd.animate.slider('panBox1', bd.g("panBox1"), ['height'], [0], [41], 0.4, function(){});
	// 	bd.animate.slider('panBox2', bd.g("panBox2"), ['height'], [0], [58], 0.6, function(){});
	// 	bd.animate.slider('panBox3', bd.g("panBox3"), ['height'], [0], [76], 0.8, function(){});
	// 	bd.animate.slider('panBox4', bd.g("panBox4"), ['height', 'left'], [0, cfgSlider.pan[3].left[screenType].start], [76, cfgSlider.pan[3].left[screenType].end], 0.8, function(){});						
	// 	bd.show('panBox1');
	// 	bd.show('panBox2');
	// 	bd.show('panBox3');
	// 	bd.show('panBox4');
	// }
	if (bd.isOutofView(cfg, 4, 'photoBox1', scrollTop)) {
		// 相册增强	
		bd.setStyles(bd.g("photoBox1"), {
			height: '0px'
			,left:  cfgSlider.photo[0].left[screenType].start + 'px'
			,visibility: 'hidden'
		});
		bd.g("photoBox1").setAttribute('data-isTweenShow', 'false');
	}else{
		// 相册增强
		bd.animate.slider('photoBox1', bd.g("photoBox1"), ['height', 'left'], [0, cfgSlider.photo[0].left[screenType].start], [149, cfgSlider.photo[0].left[screenType].end], 0.6, function(){}); 
		bd.show('photoBox1');
	}
	if (bd.isOutofView(cfg, 5, 'wenkuBox1', scrollTop)) {
		// // 贴吧神器							
		bd.setStyles(bd.g("wenkuBox1"), {
			height: '0px'
			,visibility: 'hidden'
		});	
		bd.setStyles(bd.g("wenkuBox2"), {
			height: '0px'
			,visibility: 'hidden'
		});		
		bd.g("wenkuBox1").setAttribute('data-isTweenShow', 'false');
		bd.g("wenkuBox2").setAttribute('data-isTweenShow', 'false');
	}else{			
		// 贴吧神器
		bd.animate.slider('wenkuBox1', bd.g("wenkuBox1"), ['height'], [0], [314], 0.6, function(){});
		bd.animate.slider('wenkuBox2', bd.g("wenkuBox2"), ['height'], [0], [232], 0.3, function(){});		
		bd.show('wenkuBox1');
		bd.show('wenkuBox2');
	}
	
},
/**
 * 获取页面卷起高度
 * @return {number} 返回卷起高度值
 */
bd.getScrollTop = function () {
	return (document.body.scrollTop ?  document.body.scrollTop : document.documentElement.scrollTop) || 0; 
};
bd.scrollBrowserDown = function (scrollTop, direction) {return;
	var cfg = config.boxType[screenType],
		top = 0; 
	for (var i = 1, len = 7; i <= len; i++) { 
		// top = cfg.headHeight + cfg.boxHeight * (i - 1);
		top = cfg.headHeight + cfg.boxHeight * i;
		if (scrollTop > top && scrollTop < top + cfg.boxHeight) { 
			if (bd.scrollPagePos == i + 1) {				
				return false;
			}
			
			// bd.g('downBrowserBox').style.top = top + cfg.boxHeight + 'px';
			bd.g('downBrowserBox').style.top = top + 'px';

			bd.animate.slider('downBrowserBox', bd.g('downBrowserBox'), 'opacity', 50, 100, 1, function(){ });
			bd.scrollPagePos = i + 1;				
		} 
	}
},
bd.setGoTop = function (scrollTop) { 
	if (scrollTop > 0) { 
		bd.g('goTopBox').style.display = 'block';
	} else {  
		bd.g('goTopBox').style.display = 'none';
	}
},
bd.proccessGoTop = function (scrollTop) {
	bd.g('goTop').onclick = function () {
		document.body.scrollTop = 0;
		document.documentElement.scrollTop = 0;
		// bd.animate.slider('body', document.body, 'scrollTop', scrollTop, 0, 1.2, function(){});
	}
},
bd.setStyles = function(dom, params){ 
	for(var item in params){
		dom.style[item] = params[item];
	}
},
bd.initWebPage = function () { 
	bd.statu = [0,0,0,0,0,0];	
	bd.sliderType = SchAIM.Easing.Circ.easeInOut;
	bd.prevTop = bd.getScrollTop(); 

	var scrollTopVal = 0,
		direction = 0;

	bd.proccessGoTop(scrollTopVal);
	window.onscroll = function (e) { 
		doScroll();		
	}	

	function doScroll(){
		scrollTopVal = 	bd.getScrollTop();
		direction = bd.scrollType(scrollTopVal);  	

		bd.setGoTop(scrollTopVal);
		
		downloadButton(scrollTopVal);

		bd.scrollBrowserDown(scrollTopVal, direction);

		bd.scrollPageElement(scrollTopVal, direction);	
		setTimeout(function(){
			bd.prevTop = scrollTopVal;	
		}, 20);
		
	}	
	readPageInfo();
	addDoownloadInfo();
	downloadButton(bd.prevTop);
	
	window.setTimeout(function () { 
		if (!config.loadImg[screenType][pageNum]) {			
			document.body.scrollTop = 0;
			document.documentElement.scrollTop = 0;
		}		
	}, 300);
}
function downloadButton(t, d) {
	if (t < buttonPos[0].merge) {
		bd.hide(buttonPos[1].dom);
	} else if (bd.css(buttonPos[1].dom, 'visibility')  == 'hidden'){
		bd.show(buttonPos[1].dom);
	}
}
function  addDoownloadInfo() { 
	var bt = bd.g('downBrowserBox');
	var url = decodeURIComponent(GetUrlParams('url')) || config.downInfo.url;
	var tn = GetUrlParams('tn') || config.downInfo.tn;
	var dom = null;
	for (var i = 0, len = buttonPos.length; i < len; i++) { 
		if(i == 5){
			url = 'http://dl.client.baidu.com/union/getbdbrowser.php?tn=wktest03';
			tn = 'wktest03';
		} else {
			tn = GetUrlParams('tn') || config.downInfo.tn;
		}
		dom = document.createElement('div');
		dom.innerHTML = getDownloadInfo(url, tn, config.shareText); 
		buttonPos[i].dom.appendChild(dom);
	}
}
function GetUrlParams(name){
    var reg = new RegExp("(\\?|#|&)" + name + "=([^&#]*)(&|#|$)");
    var match = location.href.match(reg);
    return (!match ? "" : match[2]);
}
function encodeHTML(str) {
	return str.replace(/&/g,'&amp;')
            .replace(/</g,'&lt;')
            .replace(/>/g,'&gt;')
            .replace(/"/g, "&quot;")
            .replace(/'/g, "&#39;");
}

function doReport(action){ 
	new Image().src = action;
}
function downBrowser(obj) {
	if (obj.getAttribute('tn') && obj.getAttribute('tn') == 'wktest03') {
		window.open('http://dl.client.baidu.com/union/getbdwebinstaller.php?tn=wktest03');
		doReport('http://xapp.baidu.com/browserlog?src=landingPage&from=' + encodeURIComponent(document.referrer) + '&tn=wktest03&action=&rnd='+(+new Date()));
		return false;
	}
	var tn = encodeHTML(GetUrlParams('tn') || 'lptest01');
	// by shichunhua 调整一个测试渠道TN策略 很恶心... 2013/07/19 19:39
	/*
	if (typeof tnItem[tn] != 'undefined') {		
		window.open('http://dl.client.baidu.com/union/getbdwebinstaller.php?tn=' + tn);
		tn = tn + 'new';
	} else {
		window.open('http://dl.client.baidu.com/union/getbdbrowser.php?tn=' + tn);
	}
	*/
	if (typeof tnItem[tn] != 'undefined') {		
		window.open('http://dl.client.baidu.com/union/getbdwebinstaller.php?tn=' + tn);
		tn = tn + 'new';
	} else if(tn == 'tiebatest03'){
		window.open('http://go.client.baidu.com/?linkid=361');
	}else {
		window.open('http://dl.client.baidu.com/union/getbdbrowser.php?tn=' + tn);
	}


	doReport('http://liulanqi.baidu.com/browserlog?src=landingPage&from=' + encodeURIComponent(document.referrer) + '&tn=' + tn + '&action=&rnd='+(+new Date()));
	doReport('http://xapp.baidu.com/browserlog?src=landingPage&from=' + encodeURIComponent(document.referrer) + '&tn=' + tn + '&action=&rnd='+(+new Date()));
}
function btnHover(obj, isHover){
	if (isHover) {
		bd.addClass(obj, 'download-hover');
	} else {
		bd.removeClass(obj, 'download-hover');
	}
}
function getDownloadInfo(url, tn, text) {
	var html = [];
	var data = "{'url': 'http://liulanqi.baidu.com/landingPage/', 'text': '百度浏览器4.0版震撼发布，划词助手、贴吧神器等多种百度增强功能，快来体验'}";
	html[html.length] = '<div class="browser-info">';
	html[html.length] = '<div class="version"></div>';
	html[html.length] = '<p class="download" link="' + url + '" tn="' + tn + '" onclick="downBrowser(this)" onmouseover="btnHover(this, true)" onmouseout="btnHover(this, false)"></p>';			
	html[html.length] = '<div class="share">';				
	html[html.length] = '<div id="bdshare" class="bdshare_t bds_tools get-codes-bdshare" data="' + data + '">';
	html[html.length] = '<span class="bds_share">分享到:</span>';					
	html[html.length] = '<a class="bds_tsina"></a>';
	html[html.length] = '<a class="bds_tqq"></a>';
	html[html.length] = '<a class="bds_qzone"></a>';
	html[html.length] = '<a class="bds_renren"></a>';					
	html[html.length] = '<span class="bds_more"></span>';					
	html[html.length] = '</div>';
	html[html.length] = '<script type="text/javascript" id="bdshare_js" data="type=tools&amp;uid=6347515" ></script>';
	html[html.length] = '<script type="text/javascript" id="bdshell_js"></script>';
	html[html.length] = '<script type="text/javascript">';
	html[html.length] = 'document.getElementById("bdshell_js").src = "http://bdimg.share.baidu.com/static/js/shell_v2.js?cdnversion=" + Math.ceil(new Date()/3600000);';
	html[html.length] = '</script>';	

	html[html.length] = '</div>';
	html[html.length] = '</div>';
	return html.join(' ');
}
function readPageInfo(){
	var info = config.boxType[screenType];
	var ids = ['downloadButton', 'downloadButton1', 'downloadButton2', 'downloadButton3', 'downloadButton4','downloadButton5'];
	for(var i = 0, iLen = ids.length ; i < iLen ; i ++){
		var btn = bd.g(ids[i]);
		var top = 0, merge = 0;
		if(i == 0){
			top = 0;
			merge = info.headHeight - 80;
		}else if(i == 1){
			top = info.headHeight;
			merge = 80;
		}else{
			top = (i - 1) * info.boxHeight + info.headHeight;
			merge = 80;
		}
		buttonPos.push({
			top: top
			,merge: merge
			,dom: btn
		});
	}
}

function fixBlockTop(){
	for(var info in config.sliderInfo){
		var arr = config.sliderInfo[info];
		for(var i = 0 , iLen = arr.length ; i < iLen ; i ++){
			var item = arr[i];
			var dom = bd.g(item.id);
			var pos = getPosition(dom);
			// item.top = pos.top;
			dom.setAttribute('data-top', pos.top);
			dom.setAttribute('data-height', item.height);
		}
	}
}



function getPosition(el){
		var ua = navigator.userAgent.toLowerCase();
		var parent = null;
		var pos = [];
		var box;
		if (el.getBoundingClientRect){ //ie
			box = el.getBoundingClientRect();
			var scrollTop = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
			var scrollLeft = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft);
			return {
				left: box.left + scrollLeft,
				top: box.top + scrollTop
			};
		}else if (document.getBoxObjectFor){ // gecko
			box = document.getBoxObjectFor(el);
			var borderLeft = (el.style.borderLeftWidth) ? parseInt(el.style.borderLeftWidth) : 0;
			var borderTop = (el.style.borderTopWidth) ? parseInt(el.style.borderTopWidth) : 0;
			pos = [box.x - borderLeft, box.y - borderTop];
		}else{ // safari & opera    
			pos = [el.offsetLeft, el.offsetTop];
			parent = el.offsetParent;
			if (parent != el) {
				while (parent) {
					pos[0] += parent.offsetLeft;
					pos[1] += parent.offsetTop;
					parent = parent.offsetParent;
				}
			}
			if (/opera/.test(ua) || (/safari/.test(ua) && el.style.position == 'absolute')) {
				pos[0] -= document.body.offsetLeft;
				pos[1] -= document.body.offsetTop;
			}
		}

		el.parentNode ? parent = el.parentNode : parent = null;

		while (parent && parent.tagName.toUpperCase() != 'BODY' && parent.tagName.toUpperCase() != 'HTML') { // account for any scrolled ancestors   
			pos[0] -= parent.scrollLeft;
			pos[1] -= parent.scrollTop;
			parent.parentNode ? parent = parent.parentNode : parent = null;
		}
		return {
			left: pos[0],
			top: pos[1]
		}	
}